// static/js/memory_curl.js

// 记忆上一次输入的内容 :
document.addEventListener('DOMContentLoaded', (event) => {
    // 恢复输入框内容
    function restoreFormData() {
        const sheetName = localStorage.getItem('sheet_name') || '';
        const caseId = localStorage.getItem('case_id') || '';
        const apiName = localStorage.getItem('api_name') || '';
        const model = localStorage.getItem('model') || '';
        const caseTitle = localStorage.getItem('case_title') || '';

        document.getElementById('sheet_name').value = sheetName;
        document.getElementById('case_id').value = caseId;
        document.getElementById('api_name').value = apiName;
        document.getElementById('model').value = model;
        document.getElementById('case_title').value = caseTitle;
    }

    // 保存输入框内容到 localStorage
    function saveFormData() {
        const sheetName = document.getElementById('sheet_name').value;
        const caseId = document.getElementById('case_id').value;
        const apiName = document.getElementById('api_name').value;
        const model = document.getElementById('model').value;
        const caseTitle = document.getElementById('case_title').value;

        localStorage.setItem('sheet_name', sheetName);
        localStorage.setItem('case_id', caseId);
        localStorage.setItem('api_name', apiName);
        localStorage.setItem('model', model);
        localStorage.setItem('case_title', caseTitle);
    }

    // 页面加载时恢复输入框内容
    restoreFormData();

    // 监听输入框的变化，保存内容
    document.getElementById('sheet_name').addEventListener('input', saveFormData);
    document.getElementById('case_id').addEventListener('input', saveFormData);
    document.getElementById('api_name').addEventListener('input', saveFormData);
    document.getElementById('model').addEventListener('input', saveFormData);
    document.getElementById('case_title').addEventListener('input', saveFormData);
});


// 获取上次输入的内容并显示 : 页面加载的时候, 将上次输入的 curl 填入 curl_command 框内
window.onload = function() {
    // 页面加载时，将之前存储的内容填入输入框
    const savedCurlCommand = localStorage.getItem('curlCommand');
    if (savedCurlCommand) {
        document.getElementById('curl_command').value = savedCurlCommand;
    }

    document.getElementById('curl_command').addEventListener('input', function() {
        localStorage.setItem('curlCommand', this.value);
    });
};
